package com.example.interviewrecorder.view

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import com.example.interviewrecorder.LyyApplicaiton
import com.example.interviewrecorder.LyyBaseActivity
import com.example.interviewrecorder.R
import com.example.interviewrecorder.databinding.ActivityPersonalDataBinding
import com.example.interviewrecorder.utils.LyyActivityCollector
import com.example.interviewrecorder.utils.toDetailDateTimeStr

/**
 * @Description 个人资料页面
 * @Author Yingyong Lao
 * @Date 2025/5/19 23:13
 */
class PersonalDataActivity : LyyBaseActivity() {
    private val binding:ActivityPersonalDataBinding by lazy {
        ActivityPersonalDataBinding.inflate(layoutInflater)
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)
        initEvents()
    }

    private fun initEvents() {
        binding.editBtn.setOnClickListener {
            EditPersonalDataActivity.start()
        }
    }

    override fun onResume() {
        super.onResume()
        initData()
    }

    @SuppressLint("SetTextI18n")
    private fun initData() {
        val currUser=LyyApplicaiton.currUser
        currUser?.let {
            binding.userNameRight.text=it.userName
            binding.passwordRight.text= "*".repeat(it.password.length)
            binding.trueNameRight.text=if (it.trueName.isEmpty()) "--" else it.trueName
            binding.genderRight.text=it.gender
            binding.ageRight.text="${it.age}${getString(R.string.age_unit)}"
            binding.emailRight.text=if (it.email.isEmpty()) "--" else it.email
            binding.registerTimeRight.text=it.registerTime.toDetailDateTimeStr()
        }
    }

    companion object{
        fun start(){
            val currAct=LyyActivityCollector.getCurrActivity()
            val intent=Intent(currAct,PersonalDataActivity::class.java)
            currAct.startActivity(intent)
        }
    }
}